package com.firewolf.mybatis;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class MainDriver {

	private SqlSession session;

	@Before
	public void init() throws IOException {
		// 1.创建一个SqlSessionFactory，这里有多种方式
		Reader reader = Resources.getResourceAsReader("conf.xml");
		SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
		// 3.打开一个SqlSession
		session = factory.openSession();

	}
	
	@After
	public void destory() throws Exception{
		session.close();
	}

	@Test
	public void testQryUserById() throws IOException {
		try {
			UserMapper uMapper = session.getMapper(UserMapper.class);
			User u = uMapper.qryUserById(1);
			System.out.println(u);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
